/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aaron.platform.entity;

import com.aaron.platform.view.FacesUtil;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 *
 * @author mac
 */
@Entity
@Table(name = "gczx_order_info")
@SequenceGenerator(name="GCZX_ORDERINFO_GENERATOR", sequenceName="GCZX_ORDERINFO_GENERATOR", allocationSize = 1)
@NamedQueries({
    @NamedQuery(name = "gczxOderInfo.findAll", query = "SELECT f FROM FgysOrderInfo f")})
public class GczxOrderInfo extends BaseObject implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final String ORDER_ID = "orderId";

    public static final String PROJECT_CODE = "projectCode";

    public static final String ORDER_CODE = "orderCode";

    public static final String ORDER_TYPE = "orderType";

    public static final String CONTACT_CODE = "contactCode";

    public static final String TASK_CODE = "taskCode";

    public static final String TASK_NAME = "taskName";

    public static final String ORDER_PRO = "orderPro";

    public static final String ORDER_STATUS = "orderStatus";

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator="GCZX_ORDERINFO_GENERATOR")
    @Column(name = "order_id")
    private Integer orderId;

    /** 订单编号 */
    @Column(name = "order_code")
    private String orderCode;

    /** 订单专业 */
    @Column(name = "order_pro")
    private int orderPro;

    /** 项目编号 */
    @Column(name = "project_code")
    private String projectCode;

    /** 合同编号 */
    @Column(name = "contact_code")
    private String contactCode;

    /** 任务编号 */
    @Column(name = "task_code")
    private String taskCode;

    /** 任务名 */
    @Column(name = "task_name")
    private String taskName;

    @Column(name = "order_desc")
    private String orderDesc;

    /** 订单金额 */
    @Column(name = "order_value")
    private double orderValue;

    /** 决算金额 */
    @Column(name = "final_value")
    private double finalValue;

    /** 决算日期：提交审计日期 */
    @Column(name = "final_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date finalDate;

    /** 审计金额 */
    @Column(name = "audited_value")
    private double auditedValue;

     /** 审计完成日期 */
    @Column(name = "audited_date")
    @Temporal(TemporalType.TIMESTAMP)
    private Date auditedDate;

    /** 累计付款金额 */
    @Column(name = "pay_value")
    private double payValue;

    /** 订单状态 */
    @Column(name = "order_status")
    private int orderStatus;

    /** 订单对应的单位信息 */
    @JoinColumn(name = "enterprise_id", referencedColumnName = "enterprise_id")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private FgysEnterprise enterpriseInfo;

    @OneToMany(mappedBy = "orderInfo", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @Fetch(FetchMode.SUBSELECT)
    private List<GczxPayDetail> payDetails;


    @JoinColumn(name = "domain_id", referencedColumnName = "domain_id")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private ItscDomainInfo domainInfo;

    public GczxOrderInfo() {
        super();
    }

    public double getAuditedValue() {
        return auditedValue;
    }

    public void setAuditedValue(double auditedValue) {
        this.auditedValue = auditedValue;
    }

    public String getContactCode() {
        return contactCode;
    }

    public void setContactCode(String contactCode) {
        this.contactCode = contactCode;
    }

    public String getOrderCode() {
        return orderCode;
    }

    public void setOrderCode(String orderCode) {
        this.orderCode = orderCode;
    }

    public int getOrderPro() {
        return orderPro;
    }

    public void setOrderPro(int orderPro) {
        this.orderPro = orderPro;
    }

    public String getDisplayOrderPro() {
        switch (this.orderPro) {
            case 1:
                return FacesUtil.getString("list_item_jz");
            case 2:
                return FacesUtil.getString("list_item_cs");
            case 3:
                return FacesUtil.getString("list_item_fgys");
            case 4:
                return FacesUtil.getString("list_item_qyw");
            default:
                return FacesUtil.getString("list_item_default");
        }
    }

    public Integer getOrderId() {
        return orderId;
    }

    public void setOrderId(Integer orderId) {
        this.orderId = orderId;
    }

    public int getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatus(int orderStatus) {
        this.orderStatus = orderStatus;
    }

    public String getDisplayOrderStatus()
    {
        double totalPay = getPayValue();

        if (totalPay < this.auditedValue || this.auditedValue == 0)
        {
            return FacesUtil.getString("list_item_executing");
        } else if (totalPay == this.auditedValue) {
            return FacesUtil.getString("list_item_finished");
        } else {
            return  FacesUtil.getString("list_item_default");
        }
    }

    public double getOrderValue() {
        return orderValue;
    }

    public void setOrderValue(double orderValue) {
        this.orderValue = orderValue;
    }

    public String getProjectCode() {
        return projectCode;
    }

    public void setProjectCode(String projectCode) {
        this.projectCode = projectCode;
    }

    public String getTaskCode() {
        return taskCode;
    }

    public void setTaskCode(String taskCode) {
        this.taskCode = taskCode;
    }

    public List<GczxPayDetail> getPayDetails() {
        return payDetails;
    }

    public void setPayDetails(List<GczxPayDetail> payDetails) {
        this.payDetails = payDetails;
    }

    public void setPayValue(double payValue) {
        this.payValue = payValue;
    }
    
    public double getPayValue() {
        return this.payValue;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public String getOrderDesc() {
        return orderDesc;
    }

    public void setOrderDesc(String orderDesc) {
        this.orderDesc = orderDesc;
    }

    public FgysEnterprise getEnterpriseInfo() {
        return enterpriseInfo;
    }

    public void setEnterpriseInfo(FgysEnterprise enterpriseInfo) {
        this.enterpriseInfo = enterpriseInfo;
    }

    public ItscDomainInfo getDomainInfo() {
        return domainInfo;
    }

    public void setDomainInfo(ItscDomainInfo domainInfo) {
        this.domainInfo = domainInfo;
    }

    public Date getAuditedDate() {
        return auditedDate;
    }

    public void setAuditedDate(Date auditedDate) {
        this.auditedDate = auditedDate;
    }

    public Date getFinalDate() {
        return finalDate;
    }

    public void setFinalDate(Date finalDate) {
        this.finalDate = finalDate;
    }

    public double getFinalValue() {
        return finalValue;
    }

    public void setFinalValue(double finalValue) {
        this.finalValue = finalValue;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final GczxOrderInfo other = (GczxOrderInfo) obj;
        if (this.orderId != other.orderId && (this.orderId == null || !this.orderId.equals(other.orderId))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 13 * hash + (this.orderId != null ? this.orderId.hashCode() : 0);
        return hash;
    }
}
